Program YunChenFileSync;

Uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
  CThreads,
{$ENDIF}{$ENDIF}
  DaemonApp, lazdaemonapp, FileSyncDeamon, FileSync, DaemonMapper, SevenZip,
  SysUtils, logger;

{$R *.res}

var
  text: string;
  n: integer;
  pass: boolean;

begin
  //注册或自定义AppClass可以响应Console事件，但服务不会启动
  //AppClass := TFileSyncApplication;
  //RegisterDaemonApplicationClass(TFileSyncApplication);

  //直接判断Console参数
  if (IsConsole) and (ParamCount = 2) and (FindCmdLineSwitch('encode', ['-', '/'], True)) then begin
      text := ParamStr(ParamCount);
      if (text.Length < 6) then
         WriteLn('Password length cannot be less than 6 chars.')
      else begin
          pass := true;
          for n := 1 to text.Length do
              if not (text[n] in [#33..#126]) then begin
                  WriteLn('The password contains an invalid character.');
                  pass := false;
                  break;
              end;
          if (pass) then
              WriteLn('The password is:' + EncodePassword(text));
      end;
  end
  else begin
    {$if declared(UseHeapTrace)}
    printleakedblock := true;
    printfaultyblock := true;
    SetHeapTraceOutput(ParamStr(0) + '.log');
    {$endIf}
    Application.Initialize;
    Application.Run;
    if (IsConsole) and ((ParamCount = 0)
      or (FindCmdLineSwitch('h', ['-', '/'], True))
      or (FindCmdLineSwitch('?', ['-', '/'], True))
      or (FindCmdLineSwitch('help', ['-', '/'], True)))
      or (FindCmdLineSwitch('encode', ['-', '/'], True) and (ParamCount <> 2))
    then
       WriteLn('  -encode text   To encode password');
    //{$if declared(UseHeapTrace)}
    //DumpHeap;
    //{$endIf}
  end;
end.
